package com.x25175.file.service;

import com.x25175.file.Vo.Query;
import com.x25175.file.Vo.StudentVo;
import com.x25175.file.entity.Student;
import com.x25175.file.mapper.StudentMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author 徐佳辉
 * @date 2020/11/19 11:29
 */
@Service
@Slf4j
public class StudentService {
    @Autowired
    private StudentMapper studentMapper;

    public boolean delete(Integer studentId) {


        return studentMapper.delete(studentId) > 0;
    }

    public boolean insert(Student student) {
        return studentMapper.insert(student) > 0;
    }

    public boolean insertDynamic(Student student) {
        return studentMapper.insertDynamic(student) > 0;
    }

    public boolean updateDynamic(Student student) {
        return studentMapper.updateDynamic(student) > 0;
    }

    public boolean update(Student student) {
        return studentMapper.update(student) > 0;
    }

    public Student selectByStudentId(Integer studentId) {
        return studentMapper.selectByStudentId(studentId);
    }

    public List<Student> selectAll() {
        return studentMapper.selectAll();
    }


    public boolean saveFromExcel(List<StudentVo> studentVo) {
        List<Student> studentList = new ArrayList<>();
        for (StudentVo vo : studentVo) {
            Student student = new Student();
            log.info("studentVo:[{}]", vo);
            BeanUtils.copyProperties(vo, student);
            //图片 pay start updateme 没加
            student.setCreateTime(new Date());
            studentList.add(student);
        }
        log.info("studentList:[{}]", studentList);
        int i = studentMapper.insertList(studentList);
        return i > 0;
    }

    public boolean updateDynamicExcluePic(Student student) {
        return studentMapper.updateDynamicExcluePic(student) > 0;
    }


    public int deletes(List<Student> students) {
        return studentMapper.deletes(students);
    }

    public List<Student> selectExact(Query query) {
        //
        List<Student> studentList = studentMapper.selectExact(query);
        return studentList;
    }

    public List<Student> selectLike(Query query) {
        //
        List<Student> studentList = studentMapper.selectLike(query);

        return studentList;
    }

    public List<Student> selectByStudentIdStringArray(String[] st) {
        List<Student> studentList = studentMapper.selectByStudentIdStringArray(st);
        return studentList;
    }

    public void deleteByStringArr(String[] split) {
        studentMapper.deleteByStringArr(split);

    }
}
